home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / DOSCOPY.C < prev    next >
Text File  |  1991-09-17  |  2KB  |  52 lines

  1. /***************************************************
  2.  *      function : copy                            *
  3.  *      purpose  : copy one file                   *
  4.  *                                                 *
  5.  *      arguments: path to source 'fromDir',       *
  6.  *                 path to target 'toDir',         *
  7.  *                 filename to copy 'fname'        *
  8.  *                                                 *
  9.  *      returns  : 0                               *
  10.  *                                                 *
  11.  *      By       :  Peter Yard (29 May 1991)       *
  12.  ***************************************************/
  13.  
  14. int copy(char *fromDir, char *fname, char *toDir)
  15. {
  16.       FILE    *nul;       /* nul will redirect stdout to DOS 'nul' */
  17.       char    from[PathSize], to[PathSize], comd[120];
  18.       int     bytesRead, oldStdout;
  19.  
  20.       /* Create the strings to describe the paths                  */
  21.  
  22.       make_path(from,fromDir,fname);
  23.       make_path(to,toDir,fname);
  24.  
  25.       /* Construct 'comd' string which is a dos command for a copy */
  26.  
  27.       strcpy(comd,"copy ");
  28.       strcat(comd,from); strcat(comd," ");
  29.       strcat(comd,to);
  30.  
  31.       /* Redirect stdout to a nul file, kills output to the screen */
  32.  
  33.       nul = fopen("NUL","w");
  34.       oldStdout = dup(STDOUT);
  35.       dup2(fileno(nul),STDOUT);
  36.       close(fileno(nul));
  37.  
  38.       system(comd);           /* COPY file */
  39.  
  40.       /* Restore stdout and close nul file */
  41.  
  42.       dup2(oldStdout,STDOUT);
  43.       close(oldStdout);
  44.  
  45.       /* Display file source and target,      */
  46.       /* otherwise comment out the next line. */
  47.  
  48.       printf("\n%s copied to %s",from,to);
  49.  
  50.       return 0;
  51. }
  52.